<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
            margin: 0;
            padding: 0;
        }
        .signal {
            width: 400px;
            height: 200px;
            border: 2px solid black;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        .light {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: gray;
            display: flex;
            justify-content: center;
            align-items: center;
            font-weight: bold;
            margin: 0 10px;
        }
        .time {
            margin-top: 20px;
            font-size: 24px;
        }
    </style>
</head>
<body>
    <div class="signal">
        <div class="light red"></div>
        <div class="light yellow"></div>
        <div class="light green"></div>
    </div>
    <div class="time">00:00</div>

    <script>
        const lights = ['red', 'yellow', 'green'];
        const durations = [15000, 3000, 15000]; 
        let totalTime = 0;
        let currentLightIndex = 0;
        function updateTime(time) {
            const timeElement = document.querySelector('.time');
            timeElement.textContent = time;
        }
        function changeLight() {
            const currentLight = document.querySelector(`.light.${lights[currentLightIndex]}`);
            currentLight.style.backgroundColor = 'gray'; 

            currentLightIndex = (currentLightIndex + 1) % lights.length; 

            const nextLight = document.querySelector(`.light.${lights[currentLightIndex]}`);
            nextLight.style.backgroundColor = lights[currentLightIndex]; 

            const remainingTime = (durations[currentLightIndex] - 1000) / 1000;
            updateTime(remainingTime);

            totalTime = 0;
            setTimeout(changeLight, durations[currentLightIndex]); 
        }
        window.onload = changeLight;
    </script>
</body>
</html>
